package service;

import dao.UserDao;
import dao.lmp.UserDaoimp;
import domain.User;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.sql.SQLException;
import java.util.List;
@WebServlet("/op")
public class loginServlet extends HttpServlet {
    UserDao userDao=new UserDaoimp();

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String username=req.getParameter("username");
        String password=req.getParameter("password");
        String address=req.getParameter("address");
        User loginUser=new User(username,password,address);
        System.out.println(username);
        System.out.println(password);
        System.out.println(address);
        try{
            int users=userDao.addUser(loginUser);
            System.out.println(users);
            if(users>0){
                System.out.println(users);
                User user=loginUser;
                req.setAttribute("u",user);
                req.getRequestDispatcher("/success").forward(req,resp);
            }else{
                req.getRequestDispatcher("/fail").forward(req,resp);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
